"use strict";
/**
 * @ Author: Yoann Meclot. MSay2
 * @ Created on: 2021-06-14 17:49:33
 * @ Modified on: 2021-06-14 17:56:26
 */
/**
 * Copyright (c) 2020-2021 MSay2 (Yoann Meclot) - @msay2/tspoet
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.Objects = void 0;
const Utils_js_1 = require("./Utils.js");
class Objects {
    static isNull(o) {
        return o == undefined || o == null;
    }
    static equals(o1, o2) {
        return o1 == o2 || !this.isNull(o1) && "equals" in o1 && o1.equals(o2);
    }
    static hash(target) {
        let bytes = 0;
        switch (typeof target) {
            case "boolean":
                bytes += 4;
                break;
            case "string":
                let code = 0;
                // from stack-O
                for (let i = 0; i < target.length; i++) {
                    let char = target.charCodeAt(i);
                    code = ((code << 5) - code) + char;
                    code |= 0;
                }
                bytes += code;
                break;
            case "number":
                bytes += Utils_js_1.UCharacter.getByte(target);
                break;
            case "object":
                bytes += 8;
                for (let prop in target)
                    bytes += this.hash(target[prop]);
        }
        return bytes;
    }
}
exports.Objects = Objects;
//# sourceMappingURL=Objects.js.map